/*
 * @lc app=leetcode.cn id=1995 lang=cpp
 *
 * [1995] 统计特殊四元组
 */

// @lc code=start
class Solution
{
public:
    int countQuadruplets(vector<int> &nums)
    {
        int f[50][50] = {0};
        int g[50][50] = {0};

        for (int a = 0; a < nums.size() - 1; a++)
            for (int b = a + 1; b < nums.size(); b++)
            {
                f[a][b] = nums[a] + nums[b];
                g[a][b] = nums[b] - nums[a];
            }

        int ans = 0;

        for (int a = 0; a < nums.size() - 3; a++)
            for (int b = a + 1; b < nums.size() - 2; b++)
                for (int c = b + 1; c < nums.size() - 1; c++)
                    for (int d = c + 1; d < nums.size(); d++)
                    {
                        ans += (f[a][b] == g[c][d]);
                    }

        return ans;
    }
};
// @lc code=end
